#pragma once
#include "common/common.h"
//make it a little prettier on the front end. 
#define details(name) (_u8*)&name,sizeof(name)

#define HEADER1 0x06
#define HEADER2 0x85


typedef struct _Transfer
{
	USART_TypeDef* _USARTx;
	_u8 * addressRx;  //address of struct
	_u8 sizeRx;       //size of struct
	_u8 * rx_buffer; //address for temporary storage and parsing buffer
	_u8 rx_array_inx;  //index for RX parsing buffer
	_u8 rx_len;		//RX packet length according to the packet

	_u8 * addressTx;  //address of struct
	_u8 sizeTx;       //size of struct

	_u8 calc_CS;	   //calculated Chacksum		
} Transfer;

Transfer * begin(_u8 *, _u8, _u8 *, _u8, USART_TypeDef* USARTx);
void sendData(const Transfer * transfer);

bool receiveData(Transfer * transfer);

/*  Edit by LAY  start */

#define CMD_MOTOR_WRITE_REG 		0x06
#define CMD_MOTOR_SET_SPEED_REG 0x43

extern int32_t g_iMoto1BiasData,g_iMoto2BiasData;


void sendMotorData(const Transfer * t,int32_t lspeed,int32_t rspeed);
bool send_Motor_Query(Transfer * t);
uint16_t CRC16(uint8_t *p,uint8_t len);
int8_t AnalyMotorData(uint8_t * ucBuffer);
/*  Edit by LAY  stop */